<?php
class SP_Helpers_Checker
{
	static public function checkLogin($str)
	{
		if (!preg_match("/^[a-zA-Z0-9_\-\.]*$/",$str))
		{return false;}
		else
		{return $str;}
	}

	static public function checkNull($str,$msg)
	{
		if ($str != "")
		{
			return $str;
		}
		else
		{
			return $msg;
		}
	}
	
	static public function checkEmail($str)
	{
		if (preg_match("/^[0-9a-z]+[\-\._0-9a-z]*@[0-9a-z]+[\-\._^0-9a-z]*[0-9a-z]+[\.]{1}[a-z]{2,6}$/",strtolower($str)))
		{
			return $str;
			
		}
		else
		{
			return false;
		}
	}

	static public function checkId($id)
	{
		if (preg_match("/^[0-9]+$/",$id))
		{
			return (int)$id;
		}
		else
		{
			return false;
		}
	}

	static public function checkPhone($str)
	{
		$chars=array('-',' ');
		$str=str_replace($chars,'',$str);
		$str = substr($str, -10);
		if (!preg_match("/^9\d{9}$/",$str))
		{
			return false;
		}
		else
		{
			return $str;
		}
	}

	static public function checkFio($str)
	{
		if ($str)
		{
			if (!preg_match("/^[".chr(0x7F)."-".chr(0xff)."a-zA-Z\-\d_\.]*$/",$str))
			{
				return false;
			}
			else
			{
				return $str;
			}
		}
		else
		return true;
	}

	static public function checkDate($date)
	{
		
		return (strtotime($date)===false) ? false : $date;

	}

	static public function checkComment($str)
	{
		if ($str)
		{
			if (preg_match("/[\'\"`]/",$str))
			{
				return false;
			}
			else
			{
				return $str;
			}
		}
		else
		return true;
	}

}